<@override name="content">
<div id="scheduler"></div>
  <#if user??>
  <i class="btn btn-info" id="evict">Evict Cache</i>
  </#if>
<p>Data Source: http://contests.acmicpc.info/contests.json</p>
<p>Author: doraemonok#163.com</p>
</@override>

<@override name="styles">
<link type='text/css' rel='stylesheet' href='assets/pnotify/jquery.pnotify.default.css'/>
<link href="assets/kendo-ui/styles/kendo.common.min.css" rel="stylesheet"/>
<link href="assets/kendo-ui/styles/kendo.default.min.css" rel="stylesheet"/>
</@override>
<@override name="scripts">
<script src='assets/pnotify/jquery.pnotify.min.js' type='text/javascript'></script>
<script src="assets/kendo-ui/js/kendo.web.min.js"></script>

<script type="text/javascript">
  $(function () {
    $("#scheduler").kendoScheduler({
      date: new Date(),
      //startTime: new Date(),
      height: 650,
      views: [
        "day",
        "week",
        "month",
        {type: "agenda", selected: true},
      ],
      editable: false,
      //timezone: "Asia/Chongqing",
      dataSource: {
        //batch: true,
        transport: {
          read: {
            url: "/api/contest/recent",
            dataType: "json"
          },
          /*update: {
              url: "http://demos.kendoui.com/service/tasks/update",
              dataType: "jsonp"
          },
          create: {
              url: "http://demos.kendoui.com/service/tasks/create",
              dataType: "jsonp"
          },
          destroy: {
              url: "http://demos.kendoui.com/service/tasks/destroy",
              dataType: "jsonp"
          },
          parameterMap: function(options, operation) {
              if (operation !== "read" && options.models) {
                  return {models: kendo.stringify(options.models)};
              }
          }*/
        },
        schema: {
          model: {
            id: "taskId",
            fields: {
              taskId: {from: "taskID", type: "number"},
              title: {from: "title", defaultValue: "No title", validation: {required: true}},
              url: {from: "url"},
              start: {type: "date", from: "start"},
              end: {type: "date", from: "end"},
              startTimezone: {from: "startTimezone"},
              endTimezone: {from: "endTimezone"},
              description: {from: "description"},
              recurrenceId: {from: "recurrenceId"},
              recurrenceRule: {from: "recurrenceRule"},
              recurrenceException: {from: "recurrenceException"},
              OJname: {from: "oj"},
              isAllDay: {type: "boolean", from: "allDay"}
            }
          }
        },
        /*filter: {
            logic: "or",
            filters: [
                { field: "ownerId", operator: "eq", value: 1 },
                { field: "ownerId", operator: "eq", value: 2 }
            ]
        }*/
      },
      resources: [
        {
          field: "OJname",
          title: "OJ",
          dataSource: [
            {text: "BNU", value: "BNU", color: "#f8a398"},
            {text: "CSU", value: "CSU", color: "#95aa98"},
            {text: "HDU", value: "HDU", color: "#51a0ed"},
            {text: "UVA", value: "UVA", color: "#66ca85"},
            {text: "Codeforces", value: "Codeforces", color: "#FF33CC"},
            {text: "HUNNU", value: "HUNNU", color: "#442585"},
            {text: "Topcoder", value: "Topcoder", color: "#DAA520"},
            {text: "SYSU", value: "SYSU", color: "#FF5555"},
            {text: "FZU", value: "FZU", color: "#EE82EE"},
            {text: "ZJU", value: "ZJU", color: "#99aa55"},
            {text: "XTU", value: "XTU", color: "#FFA500"},
            {text: "Codechef", value: "Codechef", color: "#D2B48C"},
          ]
        }
      ]
    });
  });
  $(function () {
    $('#evict').click(function () {
      if ($(this).hasClass('disabled')) {
        return;
      }
      $.get('/api/contest/evictRecent', function (data) {
        $('#evict').removeClass('btn-info').addClass('btn-success disabled');
        $.pnotify({
          title: 'Evict Success',
          text: 'Evict cache for Recent contest successfully.',
          history: false,
          type: 'success'
        });
      });
    });
  });
</script>
</@override>
<@extends name="../common/_layout.html" />
